﻿using System;
using System.Data;
using System.Collections.Generic;
using BOMS.Model;
namespace BOMS.BLL
{
    /// <summary>
    /// 业务逻辑类S_Warning 的摘要说明。
    /// </summary>
    public class S_Warning
    {
        private readonly BOMS.DAL.S_Warning dal = new BOMS.DAL.S_Warning();
        public S_Warning()
        { }
        #region  成员方法
        /// <summary>
        /// 是否存在该记录
        /// </summary>
        public bool Exists(int ID)
        {
            return dal.Exists(ID);
        }

        /// <summary>
        /// 增加一条数据
        /// </summary>
        public int Add(BOMS.Model.S_Warning model)
        {
            return dal.Add(model);
        }

        /// <summary>
        /// 更新一条数据
        /// </summary>
        public void Update(BOMS.Model.S_Warning model)
        {
            dal.Update(model);
        }

        /// <summary>
        /// 得到一个对象实体
        /// </summary>
        public BOMS.Model.S_Warning GetModel(int ID)
        {

            return dal.GetModel(ID);
        }

        /// <summary>
        /// 获得数据列表
        /// </summary>
        public DataSet GetList(string strWhere)
        {
            return dal.GetList(strWhere);
        }
       
        /// <summary>
        /// 获得数据列表
        /// </summary>
        public List<BOMS.Model.S_Warning> GetModelList(string strWhere)
        {
            DataSet ds = dal.GetList(strWhere);
            return DataTableToList(ds.Tables[0]);
        }
        /// <summary>
        /// 获得数据列表
        /// </summary>
        public List<BOMS.Model.S_Warning> DataTableToList(DataTable dt)
        {
            List<BOMS.Model.S_Warning> modelList = new List<BOMS.Model.S_Warning>();
            int rowsCount = dt.Rows.Count;
            if (rowsCount > 0)
            {
                BOMS.Model.S_Warning model;
                for (int n = 0; n < rowsCount; n++)
                {
                    model = new BOMS.Model.S_Warning();
                    dal.AssignModel(dt.Rows[n], model);
                    modelList.Add(model);
                }
            }
            return modelList;
        }

        /// <summary>
        /// 获得数据列表
        /// </summary>
        public DataSet GetAllList()
        {
            return GetList("");
        }

        /// <summary>
        /// 获得数据列表
        /// </summary>
        //public DataSet GetList(int PageSize,int PageIndex,string strWhere)
        //{
        //return dal.GetList(PageSize,PageIndex,strWhere);
        //}

        #endregion  成员方法

        public List<WarningStatus> GetWarningStatus(string Equip, string BatteryGrp, int BatteryID, DateTime dtbegin, DateTime dtend)
        {
            DataTable dt = dal.GetWarningStatus(Equip, BatteryGrp, BatteryID, dtbegin, dtend);
            List<WarningStatus> list =new List<WarningStatus>();
            for(int i=0;i<dt.Rows.Count;i++)
            {
                WarningStatus ws = new WarningStatus();
                dal.AssignWarningStatus(dt.Rows[i],ws);
                list.Add(ws);
            }
            return list;            
        }
        /// <summary>
        /// 查最新的报警列表
        /// </summary>
        /// <param name="timespan">查询时间间隔</param>
        /// <param name="NowWarningCount">目前总报警数（未处理的）</param>
        /// <returns></returns>
        public List<BOMS.Model.S_Warning> GetNewWarningData(int timespan, out int NowWarningCount)
        {
            DataTable dt  = dal.GetNewWarningData(timespan, out NowWarningCount);
            List<BOMS.Model.S_Warning> list = new List<BOMS.Model.S_Warning>();
            for (int i = 0; i < dt.Rows.Count; i++)
            {
                BOMS.Model.S_Warning model = new BOMS.Model.S_Warning();
                dal.AssignModel(dt.Rows[i], model);
                list.Add(model);
            }
            return list;
        }
        /// <summary>
        /// 求电池（组）日志表中，当前最小、最大时间
        /// </summary>
        /// <param name="Equip">设备ID</param>
        /// <param name="BatteryGrp">组号</param>
        /// <param name="BatteryID">此值为-1时，代表电池组</param>
        /// <returns>时间数组[minDtm,maxDtm]</returns>
        public DateTime?[] GetRealLogTime(string Equip, string BatteryGrp, int BatteryID)
        {
            return dal.GetRealLogTime(Equip, BatteryGrp, BatteryID);
        }
    }
}

